class Cart 

  attr_reader :cart_items

  def initialize
    @cart_items = Array.new
  end

  def add_article(article)

    cart_item = @cart_items.find{|item| item.article == article}

    if(cart_item)
      cart_item.increase_quantity
    else
      cart_item = CartItem.new(article)
      @cart_items << cart_item
    end
    cart_item  # so that we return this if we need it
  end

  def remove_article(article)
    cart_item = @cart_items.find{|item| item.article == article}

    if(cart_item.quantity > 1)
		cart_item.decrease_quantity
    else
      @cart_items.delete(cart_item)
    end
  end
  
  def delete_article(article)
	cart_item = @cart_items.find{|item| item.article == article}
     @cart_items.delete(cart_item)
  end

  def total_price
    @cart_items.sum{|item| item.price}
  end

  def total_items
    @cart_items.sum{|item| item.quantity}
  end


end